﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crude.Common;
using System.IO;

namespace Crude.Core.Repository
{
    public class LocalRepository : FileSystemRepository
    {      
        internal LocalRepository(string localRepositoryPath) : base(localRepositoryPath)
        {

        }

        public string GetPomDirectory(ProjectObjectModel pom)
        {
            string pomPath = string.Format("{0}\\{1}\\{2}\\{3}\\", RepositoryPath, pom.Name, pom.Version, DefaultConfiguration);

            if (!Directory.Exists(pomPath))
            {
                pomPath = 
                    Directory.GetDirectories(string.Format("{0}\\{1}\\{2}\\", RepositoryPath, pom.Name, pom.Version)).FirstOrDefault();
            }

            return pomPath;
        }

        public string GetPomDirectory(ProjectObjectModel pom, string configuration)
        {
            string pomPath =  string.Format("{0}\\{1}\\{2}\\{3}\\", RepositoryPath, pom.Name, pom.Version, configuration);

            if (!Directory.Exists(pomPath))
            {
                pomPath = string.Format("{0}\\{1}\\{2}\\{3}\\", RepositoryPath, pom.Name, pom.Version, DefaultConfiguration);
            }

            return pomPath;
        }


    }
}
